package engine.newUi
{
	import flash.display.MovieClip;
	import flash.events.MouseEvent;
	import flash.events.TimerEvent;
	import flash.filters.BitmapFilterQuality;
	import flash.filters.GlowFilter;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	import flash.text.TextFormat;
	import flash.utils.Timer;
	
	import newx.NxSprite;
	import newx.StageInfo;
	import newx.com.ResManager;
	import newx.com.config.StaticIni;

	/**
	 *系统公告提示 
	 * @author gaoyq
	 * 
	 */
	public class ImportantMessageUI extends NxSprite
	{
		
		private static var _self	:ImportantMessageUI;
		private var _messageTxt	:TextField;
		private var _txt			:TextField;
		private var _timer			:Timer;
		private var _textFormat	:TextFormat;
		
		private var _showing		:Boolean;
		
		private var _queueList		:Array	=	[];
		/**背景底图**/
		private var _bgMc			:MovieClip;
		
		
		/**
		 * 当完成初始化工作之后调用
		 */
		public static function getInstance():ImportantMessageUI
		{
			if(_self == null)
			{
				_self	=	new ImportantMessageUI();
			}
			return _self
		}
		
		public function ImportantMessageUI(popupUI:Boolean=true)
		{
			_timer	=	new Timer(4000,1);
			_timer.addEventListener(TimerEvent.TIMER_COMPLETE,onTimerFinish);
			_textFormat	=	new TextFormat();
			_textFormat.size			=	24;
			_textFormat.bold 			=	true;
			_textFormat.color			=	StaticIni.getIniVar("Css_txt_ImportantMessageUI", "txtStr");
			_messageTxt	=	new TextField();
			_messageTxt.mouseEnabled	=	false;
			_messageTxt.selectable		=	false;
			_messageTxt.width		=	StageInfo.rootW;
			_messageTxt.autoSize	=	TextFieldAutoSize.CENTER;
			var glow:GlowFilter		= 	new GlowFilter();
			glow.color 				= 	0x000000;
			glow.alpha 				= 	1;
			glow.blurX 				=	2;
			glow.blurY				= 	2;
			glow.strength			=	4;
			glow.quality			= 	BitmapFilterQuality.HIGH;
			_messageTxt.filters		=	[glow];
			_messageTxt.defaultTextFormat	=	_textFormat;
			_bgMc = ResManager.newResClass("CustomControl_0200") as MovieClip;
			if(_bgMc)
			{
				addChild(_bgMc);
			}
			addChild(_messageTxt);
			
			_txt					=	new TextField();
			//hide();
			
			mouseChildren	=	mouseEnabled	=	false;
			_showing = false;
		}
		
		private function onTimerFinish(e:TimerEvent):void
		{
			_messageTxt.htmlText	=	""
			
			_timer.stop();
			hide();
			
			_showing = false;
			
			showMessage();
		}
		
		private function showMessage():void
		{
			_timer.reset();
			
			if( _queueList.length > 0 && _showing == false )
			{
				_txt.htmlText = _queueList.shift();
				_messageTxt.htmlText = _txt.text;
				_messageTxt.mouseEnabled =false;
				_messageTxt.setTextFormat(_textFormat);
				StageInfo.defaultSpace.addChild(this);
				if(!_bgMc)
				{
					_bgMc = ResManager.newResClass("CustomControl_0200") as MovieClip;
					if(_bgMc)
					{
						addChildAt(_bgMc,0);
					}
				}
				if(_bgMc)
				{
					_bgMc.x = _messageTxt.x ;
					_bgMc.y = _messageTxt.y - 5;
					_bgMc.height = _messageTxt.height +10;
					_bgMc.width = _messageTxt.width;
				}
				_showing = true;
				_timer.start();
			}
		}
		
		public function showInfo(value:String):void
		{
			_queueList.push( value );
			if( !_showing )
			{//加入队列
				showMessage();
			}
		}
	}
}